package org.study.jetcache.boot.controller;

import com.alibaba.fastjson2.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.study.jetcache.boot.cache.*;
import org.study.jetcache.boot.vo.*;

import java.util.List;

/**
 * 类的描述
 *
 * @author Administrator
 * @date 2022-04-22
 */
@RestController
@RequestMapping("/jetcache")
public class CacheController {
    @Autowired
    private CardCacheComponent cardCacheComponent;
    @Autowired
    private CustomerCacheComponent customerCacheComponent;
    @Autowired
    private DictItemCacheComponent dictItemCacheComponent;

    @GetMapping("/card/{cardId}")
    public String getCard(@PathVariable("cardId") Long cardId) {
        CardVO cardVO = cardCacheComponent.getCacheValue(cardId);
        return JSON.toJSONString(cardVO);
    }

    @GetMapping("/customer/{customerId}")
    public String getCustomer(@PathVariable("customerId") Long customerId) {
        CustomerVO customerVO = customerCacheComponent.getCacheValue(customerId);
        return JSON.toJSONString(customerVO);
    }

    @GetMapping("/dictItem/{dictItemCode}")
    public String getDictItem(@PathVariable("dictItemCode") String dictItemCode) {
        List<DictItemVO> dictItemVOList = dictItemCacheComponent.getCacheValue(dictItemCode);
        return JSON.toJSONString(dictItemVOList);
    }
}
